require([
  'jquery',
  'pageInit',
  'dataTableFilter',
  'loading',
  'notification'
], function($, vamakerPage, VamDataTable, VamLoader, VamOpMsg) {
  $(function() {
    var 
      $dataTable = $('#data-table'),
      dataUrl = VAM.getVar('PMP_DATA_LIST'),
      syncListOp = VAM.getVar('SYNC_LIST_OP'),
      $filterFrm = $('#filter-frm'),
      $reportDataThead = $dataTable.find('thead'),
      $loadingWrap = new VamLoader().loader($('#list-loading-wrap')),
    listTable, tableOptions = {};
    // Table settings.
    tableOptions = {
      "dom": "<'dataTables_length table-column-filter-wrap'>l<'dataTables_length table-operate-wrap'>rftip",
      'ajax': {
        'url': dataUrl
      },
      'columns': [
        {'data': 'id'},
        {'data': 'name'},
        {'data': 'price'},
        {'data': 'resource'}
      ],
      'columnDefs': [
        {
          'targets': [0,1,3],
          'render': function (data, type, full, meta) {
            return '<p title="' + data + '">' + data +'</p>';
          }
        },
        {
          'targets': -2,
          'render': function (data, type ,full, meta) {
            resultStr = '<p class="text-success" title="' + data + '"><i class="fa fa-rmb"></i> ' + data +'</p>';
            return resultStr;
          }
        }
      ],
      'initComplete': function() {
        tableResize = new VamDataTable().columnResize($dataTable);
      },
    };
    $dataTable
    .on('preXhr.dt', function(evt) {
      $loadingWrap.show();
    });
    listTable = new VamDataTable().dataTables($dataTable, tableOptions);
    // After table data list.
    listTable.on('xhr.dt', function(evt) {
      $loadingWrap.fadeOut();
    });
    // Sync Latest PMP
    $('#Sync-latest-pmp').on('click', function(evt) {
      var $me = $(this),
          opType = $me.data('type'),
          opData;
      opData = {
        opType: opType,
        rnd: (new Date()).getTime()
      };
      $.ajax({
        url: syncListOp,
        data: opData,
        type: 'post',
        success: function(data){
          if (data.status === 'success') {
            VamOpMsg.messager(data);
            listTable.ajax.reload();
          } else {
            VamOpMsg.messager(data);
          }
        },
        alswys:function(){
        }
      })
    });
  });
});
